/**
 * Project Name:jiuselu-parent
 * File Name:UserController.java
 * Package Name:com.fxp.project.jiuselu.web.business.v1.controller.user
 * Date:2021年09月15日 17:16
 * Copyright (c) 2021, Jason.Wang All Rights Reserved.
 */
package com.fxp.project.jiuselu.web.business.v1.controller.user;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fxp.project.jiuselu.commons.rsa.RsaUtil;
import com.fxp.project.jiuselu.web.base.controller.BaseController;
import com.fxp.project.jiuselu.web.base.request.ReqBase;
import com.fxp.project.jiuselu.web.business.v1.pojo.InviteUserInfoVo;
import com.fxp.project.jiuselu.web.business.v1.pojo.UserInfoVo;
import com.fxp.project.jiuselu.web.business.v1.request.user.*;
import com.fxp.project.jiuselu.web.config.CustomerApiConfig;
import com.fxp.project.jiuselu.web.domain.CommonResult;
import com.fxp.project.jiuselu.web.models.commission.entity.JslSaleCommission;
import com.fxp.project.jiuselu.web.models.commission.service.JslCommissionService;
import com.fxp.project.jiuselu.web.models.commission.service.JslSaleCommissionService;
import com.fxp.project.jiuselu.web.models.order.entity.JslOrder;
import com.fxp.project.jiuselu.web.models.order.entity.JslOrderGoods;
import com.fxp.project.jiuselu.web.models.order.entity.JslUserBalance;
import com.fxp.project.jiuselu.web.models.order.service.IJslOrderGoodsService;
import com.fxp.project.jiuselu.web.models.order.service.IJslOrderService;
import com.fxp.project.jiuselu.web.models.order.service.IJslUserBalanceService;
import com.fxp.project.jiuselu.web.models.shareprofit.entity.JslShareProfitRecord;
import com.fxp.project.jiuselu.web.models.shareprofit.service.IJslShareProfitRecordService;
import com.fxp.project.jiuselu.web.models.user.entity.JslPcUserOauth;
import com.fxp.project.jiuselu.web.models.user.entity.JslSaleInfo;
import com.fxp.project.jiuselu.web.models.user.entity.JslUser;
import com.fxp.project.jiuselu.web.models.user.entity.JslUserOauth;
import com.fxp.project.jiuselu.web.models.user.service.IJslPcUserOauthService;
import com.fxp.project.jiuselu.web.models.user.service.IJslSaleInfoService;
import com.fxp.project.jiuselu.web.models.user.service.IJslUserOauthService;
import com.fxp.project.jiuselu.web.models.user.service.IJslUserService;
import com.fxp.project.jiuselu.web.models.userbank.entity.JslUserBankCardInfo;
import com.fxp.project.jiuselu.web.models.userbank.service.IJslUserBankCardInfoService;
import com.fxp.project.jiuselu.web.models.userbank.vo.BankCardInfoVo;
import lombok.Data;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * ClassName:UserController<br/>
 * Function: 用户的控制类<br/>
 * Date:2021年09月15日 17:16<br/>
 *
 * @author Jason.Wang
 * @version 1.0.0.0
 * @see
 * @since JDK 8
 */
@RestController
@RequestMapping("/v1/user")
public class UserController extends BaseController {

    @Autowired
    IJslUserService jslUserService;
    @Autowired
    IJslUserOauthService jslUserOauthService;
    @Autowired
    PasswordEncoder passwordEncoder;
    @Autowired
    CustomerApiConfig customerApiConfig;
    @Autowired
    private IJslSaleInfoService iJslSaleInfoService;
    @Autowired
    private IJslUserBankCardInfoService iJslUserBankCardInfoService;
    @Autowired
    private IJslPcUserOauthService jslPcUserOauthService;
    @Autowired
    private IJslOrderService orderService;

    /**
     * info: 获取当前用户信息<br/>
     *
     * @param reqBase
     * @param result
     * @return
     * @author Jason.Wang
     * @date 2021/9/15 17:18
     */
    @PostMapping("info")
    @CrossOrigin
    public CommonResult info(@RequestBody @Validated ReqBase reqBase, BindingResult result) {
        super.checkBindResult(result);
        JSONObject jsonObject = new JSONObject();
        UserInfoVo userInfoVo = jslUserService.getUserInfoVoByUserId(super.getCurrentUserInfo().getUserId());
        UserInfoVo inviteUserInfoVo = null;
        if (null != userInfoVo.getInviteId()) {
            inviteUserInfoVo = jslUserService.getUserInfoVoByUserId(userInfoVo.getInviteId());
        }
//        List<JslOrder> jslOrders = orderService.selectJslOrderNearMonth(userInfoVo.getUserId(), userInfoVo.getCreateTime());
//        if(jslOrders.size()==0){
//            JslUser user=new JslUser();
//            user.setInviteId(10003L);
//            user.setUserId(super.getCurrentUserInfo().getUserId());
//            jslUserService.updateById(user);
//        }
        JslPcUserOauth oauth = jslPcUserOauthService.getOne(new QueryWrapper<JslPcUserOauth>().eq("user_id", userInfoVo.getUserId()));
        if(oauth!=null) userInfoVo.setBind(true);
        if(userInfoVo.getLevel()==0){
            userInfoVo.setJslUserOauth(jslUserOauthService.getOne(new QueryWrapper<JslUserOauth>().eq("user_id",userInfoVo.getUserId()).eq("oauth",userInfoVo.getLevel())));
        }else {
            JslSaleInfo byUserId = iJslSaleInfoService.selectSaleInfoByBindId(super.getCurrentUserInfo().getUserId());
            if (null != byUserId) {
                userInfoVo.setSalerStatus(byUserId.getStatus());
                if (byUserId.getStatus() == 2) {
                    userInfoVo.setRemark(byUserId.getRemark());
                }
                userInfoVo.setCompanyName(byUserId.getSaleName());
                JslUserOauth one = jslUserOauthService.getOne(new QueryWrapper<JslUserOauth>().eq("user_id", byUserId.getUserId()).eq("oauth", userInfoVo.getLevel()));
                userInfoVo.setJslUserOauth(one==null?null:one);
            }
        }
        jsonObject.put("user", userInfoVo);
        jsonObject.put("invite", inviteUserInfoVo);
        return CommonResult.success(jsonObject);
    }

    /*@PostMapping("savewx")
    public CommonResult saveWxUser(@RequestBody @Validated WxReq wxreq){
        String nickname1 = wxreq.getNickname();
        Map<String, String> map=new HashMap<>();
        map.put("nickname",nickname1);
        return CommonResult.success(map);
    }*/

    /**
     * avatar: 更新当前用户的头像<br/>
     *
     * @param reqAvatar
     * @param result
     * @return
     * @author Kai.Wang
     * @date 2021/11/10 16:13
     */
    @PostMapping("avatar")
    @CrossOrigin
    public CommonResult avatar(@RequestBody @Validated ReqAvatar reqAvatar, BindingResult result) {
        super.checkBindResult(result);
        JslUser jslUser = new JslUser();
        jslUser.setUserId(super.getCurrentUserInfo().getUserId());
        jslUser.setAvatar(reqAvatar.getAvatar());
        return CommonResult.success(jslUserService.updateById(jslUser));
    }
    /**
     * nickName: 更新当前用户的昵称<br/>
     *
     * @param reqNickName
     * @param result
     * @return
     * @author Kai.Wang
     * @date 2021/11/10 16:30
     */
    @PostMapping("nickname")
    @CrossOrigin
    public CommonResult nickName(@RequestBody @Validated ReqNickName reqNickName, BindingResult result) {
        super.checkBindResult(result);
        JslUser jslUser = new JslUser();
        jslUser.setUserId(super.getCurrentUserInfo().getUserId());
        jslUser.setNickName(reqNickName.getNickName());
        return CommonResult.success(jslUserService.updateById(jslUser));
    }

    /**
     * nickName: 获取当前用户的邀请人信息<br/>
     *
     * @param reqBase
     * @param result
     * @return
     * @author Kai.Wang
     * @date 2021/11/10 16:30
     */
    @PostMapping("invite")
    @CrossOrigin
    public CommonResult invite(@RequestBody @Validated ReqBase reqBase, BindingResult result) {
        super.checkBindResult(result);
        InviteUserInfoVo inviteUserInfoVo = jslUserService.selectUserByInviteCode(super.getCurrentUserInfo().getInviteCode());
        return CommonResult.success(inviteUserInfoVo);
    }

    /**
     * company: 更新当前用户的公司信息<br/>
     *
     * @param userCompany
     * @param result
     * @return
     * @author Kai.Wang
     * @date 2021/11/10 16:30
     */
    @PostMapping("company")
    @CrossOrigin
    public CommonResult company(@RequestBody @Validated ReqUserCompany userCompany, BindingResult result) {
        super.checkBindResult(result);
        JslUser jslUser = new JslUser();
        jslUser.setUserId(super.getCurrentUserInfo().getUserId());
        jslUser.setCompanyName(userCompany.getCompanyName());
        jslUser.setIsAlter(1);
        return CommonResult.success(jslUserService.updateById(jslUser));
    }

    /**
     * company: 更新当前用户的公司信息<br/>
     *
     * @param result
     * @return
     * @author Kai.Wang
     * @date 2021/11/10 16:30
     */
    @PostMapping("online")
    @CrossOrigin
    public CommonResult online(@RequestBody @Validated JslUser jslUser, BindingResult result) {
        super.checkBindResult(result);
        jslUser.setUserId(super.getCurrentUserInfo().getUserId());
        return CommonResult.success(jslUserService.updateById(jslUser));
    }

    /**
     * password: 更新当前用户的密码<br/>
     *
     * @param reqUserPwd
     * @param result
     * @return
     * @author Kai.Wang
     * @date 2021/11/10 16:41
     */
    @PostMapping("password")
    @CrossOrigin
    public CommonResult password(@RequestBody @Validated ReqUserPwd reqUserPwd, BindingResult result) throws Exception {
        super.checkBindResult(result);
        JslUser jslUser = new JslUser();
        // 当前位手机号+ 密码登录方式
        String userPassword = null;
        try {
            userPassword = new String(RsaUtil.decryptByPrivateKey(Base64.decodeBase64(reqUserPwd.getPassword()), customerApiConfig.getPrivateKey()), StandardCharsets.UTF_8);
            jslUser.setUserId(super.getCurrentUserInfo().getUserId());
            jslUser.setPassword(passwordEncoder.encode(userPassword));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return CommonResult.success(jslUserService.updateById(jslUser));
    }


    /**
     * password: 更新当前用户的密码<br/>
     *
     * @param reqUserByInviteCode
     * @param result
     * @return
     * @author Kai.Wang
     * @date 2021/11/10 16:41
     */
    @PostMapping("/selectUserByInviteCode")
    @CrossOrigin
    public CommonResult selectUserByInviteCode(@RequestBody @Validated ReqUserByInviteCode reqUserByInviteCode, BindingResult result) throws Exception {
        super.checkBindResult(result);
        if (StringUtils.isBlank(reqUserByInviteCode.getInviteCode())) {
            return CommonResult.failed("邀请码不能为空");
        }
        InviteUserInfoVo inviteUserInfoVo = jslUserService.selectUserByInviteCode(reqUserByInviteCode.getInviteCode());
        if (null == inviteUserInfoVo) {
            return CommonResult.failed("当前邀请码不存在");
        }
        return CommonResult.success(inviteUserInfoVo);
    }

    /**
     * @return com.fxp.project.jiuselu.web.domain.CommonResult
     * @Description 设置邀请码
     * @Date 15:58 2022/1/3
     * @Param [reqUserByInviteCode, result]
     * @Author M_
     **/
    @PostMapping("/setInviteUser")
    @CrossOrigin
    public CommonResult setInviteUser(@RequestBody SetInviteUse setInviteUse, BindingResult result) throws Exception {
//        super.checkBindResult(result);
        jslUserService.setInviteUser(setInviteUse, super.getCurrentUserInfo().getUserId());
        return CommonResult.success("更新成功");
    }


    /**
     * @return com.fxp.project.jiuselu.web.domain.CommonResult
     * @Description 客户管理
     * @Date 15:58 2022/1/3
     * @Param [reqUserByInviteCode, result]
     * @Author M_
     **/
    @PostMapping("/customManager")
    @CrossOrigin
    public CommonResult customManager(@RequestBody Page page) throws Exception {
        CustomManagerByUserId customManagerByUserId = new CustomManagerByUserId();
        customManagerByUserId.setUserId(super.getCurrentUserInfo().getUserId());
        return CommonResult.success(jslUserService.customManager1(customManagerByUserId,page.getPage(),page.getPageSize()));
    }


    /**
     * 个人中心-代理管理  一级代理客户
     * @param customManagerByUserId
     * @return
     * @throws Exception
     */
    @PostMapping("/customManagerByuserId")
    @CrossOrigin
    public CommonResult customManagerByuserId(@RequestBody CustomManagerByUserId customManagerByUserId) throws Exception {
        return CommonResult.success(jslUserService.customManager(customManagerByUserId,1,10));
    }

    @Data
    static class Page{
        Integer page;
        Integer pageSize;
    }

    /**
     * @return com.fxp.project.jiuselu.web.domain.CommonResult
     * @Description 客户管理获取详细信息
     * @Date 19:46 2022/1/6
     * @Param [customManagerByUserId]
     * @Author M_
     **/
    @PostMapping("/customManagerInfo")
    @CrossOrigin
    public CommonResult customManagerInfo(@RequestBody CustomManagerByUserId customManagerByUserId) throws Exception {
        return CommonResult.success(jslUserService.customManagerInfo(customManagerByUserId));
    }


    /**
     * 用户银行卡
     *
     * @param
     * @return
     * @throws Exception
     */
    @PostMapping("/BankCardInfoListByUserId")
    @CrossOrigin
    public CommonResult queryBank() throws Exception {
        return CommonResult.success(iJslUserBankCardInfoService.selectBankCardInfoListByUserId(super.getCurrentUserInfo().getUserId()));
    }


    /**
     * @return com.fxp.project.jiuselu.web.domain.CommonResult
     * @Description 获取用户信息
     * @Date 22:18 2022/1/6
     * @Param [customManagerByUserId]
     * @Author M_
     **/
    @PostMapping("/getCustomUserMessage")
    @CrossOrigin
    public CommonResult getCustomUserMessage(@RequestBody CustomManagerByUserId customManagerByUserId) throws Exception {
        return CommonResult.success(jslUserService.getCustomUserMessage(customManagerByUserId));
    }

    /**
     * @return com.fxp.project.jiuselu.web.domain.CommonResult
     * @Description 提成管理
     * @Date 16:47 2022/1/9
     * @Param [customManagerByUserId]
     * @Author M_
     **/
    @PostMapping("/getCommission")
    @CrossOrigin
    public CommonResult getCommission() throws Exception {
        return CommonResult.success(iJslUserBankCardInfoService.selectBankCardInfoListByUserId(super.getCurrentUserInfo().getUserId()));
    }


    /**
     * @return com.fxp.project.jiuselu.web.domain.CommonResult
     * @Description 通过旧密码修改密码
     * @Date 12:29 2022/1/10
     * @Param [reqUserPwd, result]
     * @Author M_
     **/
    @PostMapping("/changePwdByPwd")
    @CrossOrigin
    public CommonResult changePwdByPwd(@RequestBody @Validated ChangePwdByPwd changePwdByPwd) throws Exception {

        jslUserService.changePwdByPwd(changePwdByPwd, super.getCurrentUserInfo().getUserId());
        return CommonResult.success("修改成功");
    }

    /**
     * @return com.fxp.project.jiuselu.web.domain.CommonResult
     * @Description //通过手机号修改密码
     * @Date 12:29 2022/1/10
     * @Param [reqUserPwd, result]
     * @Author M_
     **/
    @PostMapping("/changePwdByPhone")
    @CrossOrigin
    public CommonResult changePwdByPhone(@RequestBody @Validated ChangePwdByPhone changePwdByPhone) throws Exception {
        String newPwd1 = new String(RsaUtil.decryptByPrivateKey(Base64.decodeBase64(changePwdByPhone.getNewPwd1()), customerApiConfig.getPrivateKey()), StandardCharsets.UTF_8);
        String newPwd2 = new String(RsaUtil.decryptByPrivateKey(Base64.decodeBase64(changePwdByPhone.getNewPwd2()), customerApiConfig.getPrivateKey()), StandardCharsets.UTF_8);
        if (!newPwd1.equals(newPwd2)) {
            return CommonResult.validateFailed("两次密码输入不一致");
        }
        if (!super.validMobileCode(changePwdByPhone.getMobile(), changePwdByPhone.getCode())) {
            return CommonResult.validateFailed("验证码错误");
        }
        jslUserService.changePwdByPhone(changePwdByPhone);
        return CommonResult.success("修改成功");
    }

    /**
     * @return com.fxp.project.jiuselu.web.domain.CommonResult
     * @Description 获取手机号
     * @Date 12:29 2022/1/10
     * @Param [reqUserPwd, result]
     * @Author M_
     **/
    @PostMapping("/getUserPhone")
    @CrossOrigin
    public CommonResult getUserPhone() throws Exception {
        JslUser jslUser = jslUserService.getById(super.getCurrentUserInfo().getUserId());
        return CommonResult.success(jslUser.getUserPhone());
    }

    /**
     * @return com.fxp.project.jiuselu.web.domain.CommonResult
     * @Description 获取手机号
     * @Date 12:29 2022/1/10
     * @Param [reqUserPwd, result]
     * @Author M_
     **/
    @PostMapping("/getUserMoney")
    @CrossOrigin
    public CommonResult getUserMoney() {
        return CommonResult.success(jslUserService.getUserMoney(super.getCurrentUserInfo().getUserId()));
    }


    @Resource
    private IJslUserBalanceService jslUserBalanceService;
    @Resource
    private IJslShareProfitRecordService jslShareProfitRecordService;
    @Resource
    private IJslSaleInfoService jslSaleInfoService;

    /**
     * 余额明细分页
     * @param page 页
//     * @param pageSize 页数
//     * @param type 0全部1收入2提现
     * @return
     */
    @PostMapping("/findBalance")
    @CrossOrigin
    public CommonResult findBalance(@RequestBody BalancePage page){
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<JslUserBalance> vo = jslUserBalanceService.findByUserId(page.getPage(), page.getPageSize(), page.getType());

        return CommonResult.success(vo);
    }

    @Data
    static class BalancePage{
        Integer page;Integer pageSize;Integer type;
    }
    @Data
    static class ActingVo{
        //头像
        String url;
        //名称
        String name;
        //产生收益
        BigDecimal money;
        //下单数量
        Integer size;
        //userId
        Long userId;
        //订单id
        String orderIds;

        public ActingVo() {
        }

        public ActingVo(String url, String name, BigDecimal money, Integer size, Long userId,String orderIds) {
            this.url = url;
            this.name = name;
            this.money = money;
            this.size = size;
            this.userId = userId;
            this.orderIds=orderIds;
        }
    }

    //转正确的orderid
    public String order(List<String> list){
        StringBuilder result= new StringBuilder();
        for (String s : list) {
            if (s.length()!=25){
                s=s.substring(0,s.length()-1);
            }
            s=s+",";
            result.append(s);
        }

        if (result.length()>0){
            result = new StringBuilder(result.substring(0, result.length() - 1));
        }


        return result.toString();
    }

    @Resource
    private JslSaleCommissionService jslSaleCommissionService;

    @PostMapping("getBalanceInfo")
    @CrossOrigin
    public CommonResult getBalanceInfo(String id){

        JslSaleCommission dto = jslSaleCommissionService.getById(id);
        if (dto==null){
            return CommonResult.failed("数据错误");
        }

        return CommonResult.success(dto);
    }

    /**
     * 客户收益
     * @param userId 用户id
     * @param page 页
     * @param pageSize 页数
     * @param type 1代理的客户
     * @param lastUserId 点击团队收益人的userId
     * @return
     */
    @GetMapping("customerInfo")
    @CrossOrigin
    public com.baomidou.mybatisplus.extension.plugins.pagination.Page<ActingVo> customerInfo(Long userId, Integer page, Integer pageSize,Integer type,Long lastUserId){

        List<ActingVo> result=new ArrayList<>();
        List<JslShareProfitRecord> vos = jslShareProfitRecordService.list();
        Map<Long,String> nameMap=new HashMap<>();
        jslSaleInfoService.list().forEach(e->{
            nameMap.put(e.getBindId(),e.getSaleName());
        });


        int size=0;
        switch (type){
            //代理的客户
            case 1:
                List<JslUser> list = jslUserService.list(new QueryWrapper<JslUser>().lambda().eq(JslUser::getLevel, 0).eq(JslUser::getInviteId, userId));
                for (JslUser jslUser : list) {
                    List<JslShareProfitRecord> collect = vos.stream().filter(e -> e.getLevel() == 2 && e.getUserId().equals(userId)).collect(Collectors.toList());

                    String join = order(collect.stream().map(JslShareProfitRecord::getOrderId).collect(Collectors.toList()));

                    result.add(new ActingVo(jslUser.getAvatar(),jslUser.getNickName(),sum(collect),collect.size(),jslUser.getUserId(),join));
                }
                size=list.size();
                break;
            //代理的一级代理
            case 2:
                //代理的一级代理users
                List<JslUser> list1 = jslUserService.list(new QueryWrapper<JslUser>().lambda().eq(JslUser::getLevel, 1).eq(JslUser::getInviteId, userId));
                for (JslUser jslUser : list1) {
                    List<JslShareProfitRecord> collect = vos.stream().filter(e ->
                                    e.getLevel() == 1
                                    && e.getUserId().equals(userId)
                                    &&e.getTwoCreate().equals(jslUser.getUserId()))
                            .collect(Collectors.toList());

                    String join = order(collect.stream().map(JslShareProfitRecord::getOrderId).collect(Collectors.toList()));
                    result.add(new ActingVo(jslUser.getAvatar(),nameMap.get(jslUser.getUserId()),sum(collect),collect.size(),jslUser.getUserId(),join));
                }
                size = list1.size();
                break;
            //代理二级代理
            case 3:
                List<JslUser> list2 = jslUserService.list(new QueryWrapper<JslUser>());
                //用户下的一级代理
                List<JslUser> levels = list2.stream().filter(e -> e.getInviteId()!=null&&e.getInviteId().equals(userId) && e.getLevel() == 1).collect(Collectors.toList());
                List<Long> collect1 = levels.stream().map(JslUser::getUserId).collect(Collectors.toList());

                list2=list2.stream().filter(e->e.getLevel()==1&&collect1.contains(e.getInviteId())).collect(Collectors.toList());

                for (JslUser jslUser : list2) {
                    List<JslShareProfitRecord> collect = vos.stream().filter(e -> e.getLevel() == 0 && e.getUserId().equals(userId)&&e.getTwoCreate().equals(jslUser.getUserId())).collect(Collectors.toList());

                    String join = order(collect.stream().map(JslShareProfitRecord::getOrderId).collect(Collectors.toList()));
                    result.add(new ActingVo(jslUser.getAvatar(),nameMap.get(jslUser.getUserId()),sum(collect),collect.size(),jslUser.getUserId(),join));
                }
                size = list2.size();
                break;

            case 4:
                List<JslUser> list4 = jslUserService.list(new QueryWrapper<JslUser>().lambda().eq(JslUser::getLevel, 1).eq(JslUser::getInviteId, userId));
                for (JslUser jslUser : list4) {
                    List<JslShareProfitRecord> collect = vos.stream().filter(e -> e.getLevel() == 1 && e.getUserId().equals(userId)&&e.getTwoCreate().equals(jslUser.getUserId())).collect(Collectors.toList());

                    String join = order(collect.stream().map(JslShareProfitRecord::getOrderId).collect(Collectors.toList()));
                    result.add(new ActingVo(jslUser.getAvatar(),nameMap.get(jslUser.getUserId()),sum(collect),collect.size(),jslUser.getUserId(),join));
                }
                size = list4.size();
                break;



        }


        result=result.stream().skip((page-1)*pageSize).limit(pageSize).collect(Collectors.toList());
        return new com.baomidou.mybatisplus.extension.plugins.pagination.Page<ActingVo>().setRecords(result).setTotal(size);
    }

    @Resource
    private IJslOrderGoodsService jslOrderGoodsService;

    @Data
    static class OrderInfosVo{
        String orderIds;Integer page;Integer pageSize;
    }

    //查看详情
    @PostMapping("orderInfos")
    @CrossOrigin
    public OrderInfoVos orderInfos(@RequestBody OrderInfosVo vo){
        String orderIds = vo.getOrderIds();
        Integer page = vo.getPage();
        Integer pageSize = vo.getPageSize();

        //消费总额
        Integer sum=0;
        //下单数量
        BigDecimal money = new BigDecimal("0.00");

        List<OrderInfoVo> vos=new ArrayList<>();
        int size=0;
        if (!orderIds.equals("[]")){
            String[] split = orderIds.split(",");
            List<String> list = Arrays.asList(split);

            size = list.size();
            list=list.stream().skip((page-1)*pageSize).limit(pageSize).collect(Collectors.toList());
            List<JslOrder> orderList = orderService.list(new QueryWrapper<JslOrder>().lambda().in(list.size() != 0, JslOrder::getOrderId, list));
            for (JslOrder order : orderList) {
                List<JslOrderGoods> list1 = jslOrderGoodsService.list(new QueryWrapper<JslOrderGoods>().lambda().eq(JslOrderGoods::getOrderId, order.getOrderId()));
                money=money.add(order.getTotalAmount());
                sum=sum+list1.size();
                vos.add(new OrderInfoVo(order.getOrderId(),order.getTotalAmount(),order.getPayTime(),list1.size()));
            }
        }


        return new OrderInfoVos(new com.baomidou.mybatisplus.extension.plugins.pagination.Page<OrderInfoVo>().setRecords(vos).setTotal(size),sum,money);
    }

    @Data
    static class OrderInfoVos{
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<OrderInfoVo> page;
        Integer sum;
        BigDecimal money;

        public OrderInfoVos() {
        }

        public OrderInfoVos(com.baomidou.mybatisplus.extension.plugins.pagination.Page<OrderInfoVo> page, Integer sum, BigDecimal money) {
            this.page = page;
            this.sum = sum;
            this.money = money;
        }
    }

    @Data
    static class OrderInfoVo{
        //订单号
        String orderId;
        //金额
        BigDecimal total;
        //时间
        LocalDateTime time;
        //数量
        Integer sum;

        public OrderInfoVo() {
        }

        public OrderInfoVo(String orderId, BigDecimal total, LocalDateTime time, Integer sum) {
            this.orderId = orderId;
            this.total = total;
            this.time = time;
            this.sum = sum;
        }
    }

    //计算
    public BigDecimal sum(List<JslShareProfitRecord> vos){
        BigDecimal result=new BigDecimal("0.00");
        for (JslShareProfitRecord vo : vos) {
            result=result.add(vo.getProfitMoney());
        }
        return result;
    }



}
@Data
class FindBalance{
    int current;
    int page;
    int pages;
    List<JslUserBalance> records;
    long total;

    public FindBalance() {
    }

    public FindBalance(int current, int page, int pages, List<JslUserBalance> records, long total) {
        this.current = current;
        this.page = page;
        this.pages = pages;
        this.records = records;
        this.total = total;
    }
}